package com.campus.wall.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.campus.wall.R;
import com.campus.wall.response.MessageResponse;
import com.campus.wall.ui.SendMsgActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class SendMsgAdapter<T> extends BaseAdapter {
    private Activity context;
    @Nullable
    private List<T> datas;

    public SendMsgAdapter(SendMsgActivity sendMsgActivity, List<T> datas) {
        this.context = context;
        if (datas == null) {
            datas = new ArrayList<>();
        }
        this.context=sendMsgActivity;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public T getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int i, View contentview, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (null == contentview) {
            viewHolder = new ViewHolder();
            contentview = LayoutInflater.from(context).inflate(R.layout.layout_msg_item, null);
            viewHolder.type0= (RelativeLayout) contentview.findViewById(R.id.type0);
            viewHolder.type1= (RelativeLayout) contentview.findViewById(R.id.type1);
            viewHolder.msg0= (TextView) contentview.findViewById(R.id.msg0);
            viewHolder.msg1= (TextView) contentview.findViewById(R.id.msg1);
            contentview.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) contentview.getTag();
        }
        final MessageResponse response = (MessageResponse) getItem(i);
        if(response.getType()==0){
            viewHolder.type0.setVisibility(View.VISIBLE);
            viewHolder.msg0.setText(response.getMessage());
        }else {
            viewHolder.type1.setVisibility(View.VISIBLE);
            viewHolder.msg1.setText(response.getMessage());
        }
        return contentview;
    }
    class ViewHolder {
        public RelativeLayout type0;
        public RelativeLayout type1;
        public TextView msg0;
        public TextView msg1;
    }
}
